package cn.laixueit.controller;

import cn.laixueit.base.BaseController;
import cn.laixueit.base.R;
import cn.laixueit.pojo.BookChapter;
import cn.laixueit.pojo.Soft;
import cn.laixueit.service.BookService;
import cn.laixueit.service.SoftService;
import cn.laixueit.vo.BookVo;
import cn.laixueit.vo.SoftVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author duxiang
 * @date 2023/11/29 9:39
 */

@RestController
@RequestMapping("/home")
@CrossOrigin
public class WEBController extends BaseController {
    @Resource
    private SoftService softService;
    @Resource
    private BookService bookService;

    @PostMapping("softpage/{page}/{size}")
    public R softpage(@PathVariable(name = "page")Integer page,
                  @PathVariable(name = "size")Integer size,
                  @RequestBody SoftVo softvo){
        Page<Soft> pageInfo = new Page<>(page, size);
        return softService.softpage(pageInfo,softvo);
    }

    @GetMapping("/softgetRow/{id}")
    public R softgetRow(@PathVariable("id") String id){
        Soft soft = softService.getById(id);
        return R.ok().put("obj",soft);
    }

    @GetMapping("/softdetail/{id}")
    public R softdetail(@PathVariable("id") String id){
         R r = softService.softdetail(id);
        return r;
    }

    @GetMapping("/book/list")
    public R list(BookVo bookvo){
        return bookService.listBookAndOneChapters(bookvo);
    }


    @GetMapping("/book/chapter/list")
    public R chapterList(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "999") Integer size,
                         BookChapter chapter){
        Page<BookChapter> chapterPage = new Page<>(page,size);
        return bookService.chapterList(chapterPage,chapter);
    }


    @GetMapping("/book/content")
    public R chapterContent(@RequestParam String id){
        return bookService.chapterContent(id);
    }

}
